import Main from "@/view/main/main";
import parentView from "@/components/parent-view";
import router from "@/router";
import store from "@/store";
/**
 * iview-admin中meta除了原生参数外可配置的参数:
 * meta: {
 *  hideInMenu: (false) 设为true后在左侧菜单不会显示该页面选项
 *  notCache: (false) 设为true后页面不会缓存
 *  access: (null) 可访问该页面的权限数组，当前路由设置的权限会影响子路由
 *  icon: (-) 该页面在左侧菜单、面包屑和标签导航处显示的图标，如果是自定义图标，需要在图标名称前加下划线'_'
 *  hideInNav:(false) 设为false，导航面包屑不会显示该菜单
 * }
 */
let configRouter = [
  {
    path: "/",
    name: "login",
    meta: {
      title: "Login - 登录",
      hideInMenu: true
    },
    component: () => import(/*webpackChunkName: "login"*/"@/view/login/login.vue")
  },
  {
    path: '/401',
    name: 'error_401',
    meta: {
      hideInMenu: true
    },
    component: () => import(/*webpackChunkName: "401"*/'@/view/error-page/401.vue')
  },
  {
    path: '/500',
    name: 'error_500',
    meta: {
      hideInMenu: true
    },
    component: () => import(/*webpackChunkName: "500"*/'@/view/error-page/500.vue')
  },
  {
    path: '*',
    name: 'error_404',
    meta: {
      hideInMenu: true
    },
    component: () => import(/*webpackChunkName: "404"*/'@/view/error-page/404.vue')
  },
  {
    path: "/main",
    name: "总概",
    meta: {
      title: "总概",
      hideInNav: true
    },
    component: Main,
    children: [
      {
        path: "home",
        name: "home",
        meta: {
          icon: "md-menu",
          title: "总概"
        },
        component: () => import(/*webpackChunkName: "home"*/"@/view/home/home.vue")
      }
    ]
  },
  {
    path: "/multilevel",
    name: "multilevel",
    meta: {
      icon: "md-menu",
      title: "多级菜单"
    },
    component: Main,
    children: [
      {
        path: "level_2_1",
        name: "level_2_1",
        meta: {
          icon: "arrow-graph-up-right",
          title: "二级-1"
        },
        component: () => import(/*webpackChunkName: "level-2-1"*/"@/view/multilevel/level-2-1.vue")
      },
      {
        path: "level_2_2",
        name: "level_2_2",
        meta: {
          icon: "arrow-graph-up-right",
          showAlways: true,
          title: "二级-2",
          access: ["super_admin"]
        },
        component: parentView,
        children: [
          {
            path: "level_2_2_1",
            name: "level_2_2_1",
            meta: {
              icon: "arrow-graph-up-right",
              title: "三级"
            },
            component: () => import("@/view/multilevel/level-2-2/level-3-1.vue")
          }
        ]
      },
      {
        path: "level_2_3",
        name: "level_2_3",
        meta: {
          icon: "arrow-graph-up-right",
          title: "二级-3"
        },
        component: () => import("@/view/multilevel/level-2-3.vue")
      }
    ]
  },
  {
    path: "/",
    name: "测试",
    meta: {
      title: "测试",
      hideInNav: false
    },
    component: Main,
    children: [
      {
        path: "test",
        name: "test",
        meta: {
          icon: "md-menu",
          title: "测试",
          hideInNav: true
        },
        component: () => import(/*webpackChunkName: "test"*/ "@/view/test/test.vue")
      },
      {
        path: "/main/test-list-a",
        name: "test-list-a",
        meta: {
          title: "testListA",
          hideInMenu: true,
          hideInNav: true
        },
        component: () => import("@/view/test/view/test-list-a.vue")
      },
      {
        path: "/main/test-list-b",
        name: "test-list-b",
        meta: {
          title: "testListB",
          hideInMenu: true,
          hideInNav: true
        },
        component: () => import("@/view/test/view/test-list-b.vue")
      }
    ]
  }
];

router.addRoutes(configRouter);

store.commit('setRouter',configRouter);

router.beforeEach((to, from, next) => {
  router.customBeforeEach(to, from, next, configRouter);
});

router.afterEach(to => {
  router.customAfterEach(to);
});

export default router;
